package com.netty.demo;

import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;

/**
 * @Created on 2021/4/13.
 * @Author by zbk
 * @Description:
 */
public class TestByteBufferString {

    public static void main(String[] args) {


        // 普通方法
        ByteBuffer buffer1 = ByteBuffer.allocate(10);
        buffer1.put("hello".getBytes());
        buffer1.flip();
        System.out.println((char) buffer1.get());


        // warp
        ByteBuffer buffer2 = ByteBuffer.wrap("hello".getBytes());

        //charset
        ByteBuffer buffer3 = StandardCharsets.UTF_8.encode("hello");
        System.out.println(StandardCharsets.UTF_8.decode(buffer3));


    }
}
